// pages/patient/patientinfo/patientinfo.js
var api = require("../../../config/api.js");
var utils = require("../../../utils/util.js");
const app = getApp();

var patientId = -1;

Page({

  /**
   * 页面的初始数据
   */
  data: {
    infos: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

    if(options.patientId){
      patientId = options.patientId;
    }

    this.setScrollHeight();
    this.loadPatientInfo();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },

   // 设置scroll view的高度
   setScrollHeight: function(){
    let that = this;
    wx.getSystemInfo({
      success: function(res){
        let windowHeight = res.windowHeight;
        let screenHeight = res.screenHeight;
        console.log("windowHeight = " + windowHeight);
        console.log("screenHeight = " + screenHeight);
        let componentWrap = wx.createSelectorQuery();
        componentWrap.select('#complication').boundingClientRect();
        let complicationHeight = 0;
        componentWrap.exec(function (res) {
          console.log("complication height = " + res[0].height);
          complicationHeight = res[0].height;
          var temp = windowHeight - complicationHeight;
          console.log("scroll height = " + temp );
          that.setData({
            scrollHeight: temp
          });
        });
      }
    });
  },

  loadPatientInfo: function(){
    let that = this;
    
    console.log('loadPatientInfo patientId = ' + patientId);

    utils.request(api.getPatientInfo, {
      id: patientId
    }).then(function(res){
      console.log("loadPatientInfo= " + JSON.stringify(res));
      var temp = res.data;
      var info = [
        {
          name: '姓名',
          type: 'text',
          value: temp.name
        },
        {
          name: '性别',
          type: 'text',
          value: temp.sex == 0? '男':'女'
        },
        {
          name: '手机号',
          type: 'text',
          value: temp.phone
        },
        {
          name: '生日',
          type: 'text',
          value: utils.timestampFormatDate(temp.birthday, 'yyyy-MM-dd')
        },
        {
          name: '年龄',
          type: 'text',
          value: utils.getAge(temp.birthday)
        },
        {
          name: '身高',
          type: 'text',
          value: temp.height
        },
        {
          name: '体重',
          type: 'text',
          value: temp.weight
        },
        {
          name: '民族',
          type: 'text',
          value: temp.nation
        },
        {
          name: '置管手臂',
          type: 'text',
          value: temp.arm        
        },
        {
          name: '置管部位',
          type: 'text',
          value: temp.place        
        },
        {
          name: '置管静脉',
          type: 'text',
          value: temp.vein        
        },
        {
          name: '置管朝向',
          type: 'text',
          value: temp.orien        
        },
        {
          name: '穿刺阶段',
          type: 'text',
          value: temp.phase        
        },
        {
          name: '终点事件',
          type: 'text',
          value: temp.terminal        
        }
      ];
      that.setData({
        infos: info
      });
    });
  },
})